package com.atqh.srrt.chicken.controller.BlogController;

import com.atqh.srrt.chicken.Aop.LogAnnotation;
import com.atqh.srrt.chicken.Cache.Cache;
import com.atqh.srrt.chicken.Vo.params.ArticleParam;
import com.atqh.srrt.chicken.Vo.params.PageParams;
import com.atqh.srrt.chicken.service.ArticleService;
import com.atqh.srrt.chicken.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("articles")
@CrossOrigin
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    /**
     * 分页查询，文章列表
     */
    @PostMapping("/list")
    @LogAnnotation(module = "文章模块", operator = "获取文章列表")
    @Cache(expire = 5 * 60 * 1000, name = "listArticle")
    public Result listArticle(@RequestBody PageParams pageParams) {
        return articleService.listArticle(pageParams);
    }

    /**
     * @return
     */
    @RequestMapping("/hot")

    public Result hotArticle() {
        int limit = 8;
        return articleService.hotArticle(limit);
    }

    /**
     * @return
     */
    @RequestMapping("/new")
    public Result newArticle() {
        int limit = 5;
        return articleService.newArticle(limit);
    }

    /**
     * @作者：大叔azhe
     * @api：查看文章詳情接口
     * @创建时间：16:08 2022/8/17
     */
    @RequestMapping("/view/{id}")
    @LogAnnotation(module = "文章模块", operator = "查看文章详情")
    @Cache(expire = 5*60*1000,name = "ArticleDetial")
    public Result findArticleById(@PathVariable("id") Long articleId) {
        return articleService.findArticleById(articleId);
    }

    @PostMapping("/publish")
    @LogAnnotation(module = "文章模块", operator = "发布文章")
    public Result publish(@RequestBody ArticleParam articleParam) {
        return articleService.publish(articleParam);
    }

    @PostMapping("{id}")
    public Result articleById(@PathVariable("id") Long articleId) {
        return articleService.findArticleById(articleId);
    }
}
